<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>角色编辑</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <style type="text/css">
        body {
            margin:0;
            padding:0;
            border:0;
            width:100%;
            height:100%;
            overflow:hidden;
        }
    </style>
</head>
<body>
<form id="form1" method="post">
    <!-- 角色 编辑框START-->
    <div id="editform" class="form" style="padding:20px;">
        <table align="center">
            <tr>
                <td style="width: 80px"><font color="#dc143c">*</font>角色编号:</td>
                <td>
                    <input name="id" id="id" class="mini-textbox" style="width: 180px" allowSort="true" required="true" />
                </td>
            </tr>
            <tr>
                <td style="width: 70px"><font color="#dc143c">*</font>角色名称:</td>
                <td>
                    <input name="name" class="mini-textbox" style="width: 180px" required="true" allowSort="true" emptyText="" />
                </td>
            </tr>
            <tr>
                <td style="width: 140px"><font color="#dc143c">*</font>角色对应机构级别:</td>
                <td>
                    <input id="orgLevel" name="orgLevel" class="mini-combobox" style="width:180px;" required="true" popupMaxHeight="320px" alwaysView
                           textField="name" valueField="id" emptyText="请选择..." />
                </td>
            </tr>
            <tr>
                <td style="width: 70px;">是否禁用:</td>
                <td>
                    <input name="stat" class="mini-radiobuttonlist" style="width: 150px"
                           value="1" data="[{id: 0, text: '禁用'}, {id: 1, text: '启用'}]" required="true" />
                </td>
            </tr>
        </table>
    </div>
    <!-- 角色 编辑框END-->
    <div style="padding:2px;margin: 22px;text-align: center">
        <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">保存</a>
        <a class="mini-button" iconCls="fa-close" plain="true" onclick="onCancel()">取消</a>
    </div>
</form>

<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var orgLevel = mini.get("orgLevel");

    //标准方法接口定义
    function SetData(data) {
        orgLevelList();
        var o = mini.decode(data);

        if (o.action != "add") {
            mini.getbyName("id").disable();
        }
        form.setData(o);
        form.setChanged(false);
    }

    function saveData() {
        //如果是新增需要判断数据库中是否存在该岗位编号
        var mark = false;
        if (${flag!} == 1) {
            $.ajax({
                url: "/basic/role/" + mini.get("id").getValue(),
                cache: false,
                async: false,
                success: function (success) {
                    if (success.code == 1) {
                        mark = true;
                    } else {

                    }
                }
            });
        }
        if (mark == true) {
            mini.alert("该角色已存在");
        } else {
            form.validate();
            if (form.isValid() == false) {
                return;
            }
            var data = form.getData();
            var json = mini.encode(data);
            commonSaveData("/basic/role/save", {data: json}, callback);

            // 保存成功的回调函数
            function callback() {
                mini.alert("保存成功", "成功", window.CloseOwnerWindow);
            }
        }
    }

    function orgLevelList() {
        commonComboBoxSearch("/basic/common/getOrgLevelList", {data: -1}, callback);

        function callback(success) {
            var orgLevelName = mini.get("orgLevel");
            orgLevelName.load(mini.decode(success));
        }
    }
</script>
</body>
</html>